/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import gui.MainView;
import dao.ConnectionManager;
import gui.GUIUtils;
import gui.LoginView;
import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 * @author Alessio
 */
public class LoginController {
    private static LoginController instance = new LoginController();
    
    public static LoginController getInstance() {
        return instance;
    }
    
    private LoginView view;

    public void setView(LoginView view) {
        this.view = view;
    }

    public void connect() {
        try {
            ConnectionManager.setup(view.getHost() + ":" + view.getPort(), view.getUsername(), view.getPassword());
            Connection con = ConnectionManager.getConnection();
            con.close();
            MainView.getInstance().loginDone();
            
        } catch (SQLException ex) {
            GUIUtils.showError(ex.getMessage());
        } catch (ClassNotFoundException ex) {
            GUIUtils.showError(ex.getMessage());
        }
    }
    
    
}
